﻿using System.Collections.Generic;

namespace OneDark.Sqlite
{
    internal class DBHelper
    {
        private static Stack<DBHelper> mInstancePool = new Stack<DBHelper>();
        private static object mLockIntancePool = new object();

        public static DBHelper GetInstance()
        {
            DBHelper dbHelper = null;
            lock (mLockIntancePool)
            {
                if (mInstancePool.Count != 0)
                {
                    dbHelper = mInstancePool.Pop();
                }
                else
                {
                    dbHelper = new DBHelper();
                }
            }
            return dbHelper;
        }

        public static void ReleaseInstance(DBHelper dbHelper)
        {
            lock (mLockIntancePool)
            {
                mInstancePool.Push(dbHelper);
            }
        }

        static DBHelper()
        {
            for (int i = 0; i < 10; i++)
            {
                mInstancePool.Push(new DBHelper());
            }
        }

        private DBHelper()
        {
            var mConnection = new GITDB();
        }
    }
}